public class Recursion {

    public static void main(String[] args) {
        int[][]arr = new int[8][7];
        Recur re = new Recur();
        int[][] map =  re.wall(arr);
        for (int i = 0; i < map.length; i++) {
            for (int j = 0; j < map[i].length; j++) {
                System.out.print(map[i][j]+" ");
            }
            System.out.println();
        }

        System.out.println("==========走迷宫的小老鼠===========");
        re.findway(1,1,map);
        System.out.println();
        for (int i = 0; i < map.length; i++) {
            for (int j = 0; j < map[i].length; j++) {
                System.out.print(map[i][j]+" ");
            }
            System.out.println();
        }

    }

}


class Recur{
    
//    public 
//    围墙
    public int[][]  wall(int [][]arr){
          arr = new int[8][7];
        for (int i = 0; i < 7; i++) {
            arr[0][i] = 1;
            arr[7][i] = 1;
        }
        arr[3][1] = 1;
        arr[3][2] = 1;
        for (int  j = 0;  j < 8;  j++) {
            arr[j][0] = 1;
            arr[j][6] = 1;
        }
        return arr;
    }

    public boolean findway(int i,int j,int[][] map){
        // 先判断是否越界
        if (i < 0 || i >= map.length || j < 0 || j >= map[0].length) {
            return false;
        }
      if(map[5][6] == 2){
          return true;
      }else{
          if(map[i][j] == 0){
              map[i][j] = 2;

              if(findway(i+1,j,map)){
                  return true;
              }else if(findway(i,j+1,map)){
                  return true;
              } else if (findway(i - 1, j, map)) {
                  return true;
              } else if (findway(i,j-1 ,map)) {
                  return true;
              } else{
                  map[i][j] = 3;
                  return false;
              }

          }else{
              return false;
          }
      }
    }
    
}